package top.malaoshi.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.entity.Book;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestRedisTemplateCtrl {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @RequestMapping("/redisTemplate")
    public void test(){
        redisTemplate.boundValueOps("name").set("lilei");

    }

    @RequestMapping("/object")
    public void testObject(){
        Book book=new Book();
        book.setName("redis入门到高级");
        book.setAuthor("韩梅梅");
        redisTemplate.boundValueOps("book").set(book);
    }
    @RequestMapping("/getObject")
    public void testGetObject(){
        Book book=(Book)redisTemplate.boundValueOps("book").get();

        System.out.println(book);
    }
}
